<?php
/**
 * Created by PhpStorm.
 * User: g
 * Date: 2017/4/27
 * Time: 14:57
 */

namespace app\front\controller;


use app\common\controller\Base;
use think\Session;

class Login extends Cms
{
    public function login(){
        return $this->fetch();
    }

    public function doLogin(){
        $user_name = input('user_name');
        $user_pass = input('user_pass');
        $user_info = db("account_registration")->where(["username"=>$user_name])->find();
        if(!$user_info){
            return $this->ret->setCode(1)->setMsg("登录失败，用户不存在");
        }else{
            //$user_info = $user_info->toArray();
            $confirm_pwd = inge_encryption_pwd($user_pass,"Rake");
            if($confirm_pwd == $user_info['userpass']){
                unset($user_info['userpass']);
                Session::set('u_info',$user_info);
                Session::set("u_id",$user_info['id']);
                return $this->ret->setCode(0)->setMsg('登陆成功')->toJson();
            }else{
                return $this->ret->setCode(1)->setMsg("登录失败，密码错误")->toJson();
            }
        }
    }

    public function logOut(){
        session(null);
        $this->success("退出成功",url("/front/1"));
    }
}